<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/8/9
 * Time: 9:44
 */

namespace app\api\controller;


use think\Db;

class Home extends Base
{
    private $user_id;
    private $create_time;
    private $page;
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
    }
    public function getPoint(){
        extract (input());
        if(isset($sheng)){
            $shengID = Db::table('up_area')
                ->where(['district'=>$sheng,'level'=>1])
                ->value('district_id');
            $res['sheng'] = $shengID;
        }
        if(isset($shi)){
            $shiID = Db::table('up_area')
                ->where(['district'=>$shi,'level'=>2])
                ->value('district_id');
            $res['shi'] = $shiID;
        }
        if(isset($qu)){
            $quID = Db::table('up_area')
                ->where(['district'=>$qu,'level'=>3])
                ->value('district_id');
            $res['qu'] = $quID;
        }
        return json(['status'=>200,'msg'=>$res]);
    }
    /**
     * 轮播图列表
     * @return \think\response\Json
     */
    public function bannerList(){
        $banner = Db::table('up_banner')
            ->where('banner_status', 1)
            ->field('banner_id, banner_image')
            ->order('banner_sort desc')
            ->select();
        if($banner){
            return json(['status' => 200, 'msg' => $banner]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    /**
     * 本机
     * @return \think\response\Json
     */
    public function getMyPhone(){
        $all_name = input('all_name');
        $banner = Db::table('up_models')
            ->where('models_all_name', 'like','%,'.$all_name.',%')
            ->whereOr('models_name', $all_name)
            ->field('models_id, models_image, models_name, models_max_recycle_price')
            ->find();
        if($banner){
            $banner['models_max_recycle_price'] = (int)$banner['models_max_recycle_price'];
            return json(['status' => 200, 'msg' => $banner]);
        }else{
            return json(['status' => 200, 'msg' => '']);
        }
    }
    
    /**
     * 轮播详情
     * @return \think\response\Json
     * banner_id     轮播图ID
     */
    public function bannerDetail(){
        $banner_id = input('banner_id');
        $detail = Db::table('up_banner')
            ->where('banner_id', $banner_id)
            ->field('banner_title, banner_image, banner_content, banner_time')
            ->find();
        return json(['status' => 200, 'msg' => $detail]);
    }
}